home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / split.c < prev    next >
C/C++ Source or Header  |  1995-05-15  |  3KB  |  171 lines

  1. /* split.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5.  
  6. /* $Id: split.c,v 4.15 1995/05/15 12:20:07 espie Exp espie $
  7.  * $Log: split.c,v $
  8.  * Revision 4.15  1995/05/15  12:20:07  espie
  9.  * *** empty log message ***
  10.  *
  11.  * Revision 4.14  1995/05/12  13:53:34  espie
  12.  * New synchronization.
  13.  *
  14.  * Revision 4.13  1995/04/22  17:50:27  espie
  15.  * *** empty log message ***
  16.  *
  17.  * Revision 4.12  1995/02/21  17:54:32  espie
  18.  * Internal problem: buggy RCS. Fixed logs.
  19.  *
  20.  * Revision 4.0  1994/01/11  17:56:24  espie
  21.  * Cleaner.
  22.  * run_in_fg() and create_notes_table() not needed !
  23.  * Use new pref scheme.
  24.  */
  25.      
  26.  
  27. #include <signal.h>
  28.      
  29. #include "defs.h"
  30. #include "song.h"
  31. #include "extern.h"
  32.      
  33. #include "getoption.h"
  34.      
  35. ID("$Id: split.c,v 4.15 1995/05/15 12:20:07 espie Exp espie $")
  36.  
  37. /* global variable to catch various types of errors
  38.  * and achieve the desired flow of control
  39.  */
  40. int error;
  41.  
  42. LOCAL struct song *do_scan_song(name, type)
  43. char *name;
  44. int type;
  45.    {
  46.    struct song *song;
  47.    struct exfile *file;
  48.  
  49.    file = open_file(name, "r", getenv("MODPATH"));
  50.    if (!file)
  51.       return NULL;
  52.    song = read_song(file, type); 
  53.    close_file(file);
  54.    return song;
  55.    }
  56.  
  57. #define CHUNK_SIZE 32000
  58.  
  59. LOCAL char *suffix[] =
  60.    {
  61.    "lzh", "lha", "Z", "z", "shn", "zoo", 0
  62.    };
  63.  
  64. LOCAL void truncate(name)
  65. char *name;
  66.    {
  67.    int i;
  68.    int last_point = 0;
  69.  
  70.    for (i = 0; name[i]; i++)
  71.       {
  72.       if (name[i] == '.')
  73.          last_point = i + 1;
  74.       }
  75.    if (last_point)
  76.       {
  77.       for (i = 0; suffix[i]; i++)
  78.       if (strcmp(name + last_point, suffix[i]) == 0)
  79.          {
  80.          name[last_point - 1] = 0;
  81.          return;
  82.          }
  83.       }
  84.    }
  85.  
  86.    
  87.    
  88. void split_module(name, cutpoint)
  89. char *name;
  90. long cutpoint;
  91.    {
  92.    char buffer[300];
  93.    FILE *mod;
  94.    FILE *samp;
  95.    struct exfile *file;
  96.    char *copy_buff;
  97.    int chunk;
  98.  
  99.    file = open_file(name, "r", getenv("MODPATH"));
  100.    truncate(name);
  101.    sprintf(buffer, "%s.mod", name);
  102.    mod = fopen(buffer, "w");
  103.    if (!mod)
  104.       exit(10);
  105.    sprintf(buffer, "%s.samp", name);
  106.    samp = fopen(buffer, "w");
  107.    if (!samp)
  108.       exit(10);
  109.    copy_buff = malloc(CHUNK_SIZE);
  110.    if (!copy_buff)
  111.       exit(10);
  112.    while(cutpoint >= CHUNK_SIZE)
  113.       {
  114.         read_file(copy_buff, 1, CHUNK_SIZE, file);
  115.       fwrite(copy_buff, 1, CHUNK_SIZE, mod);
  116.       cutpoint -= CHUNK_SIZE;
  117.       }
  118.    if (cutpoint > 0)
  119.       {
  120.       read_file(copy_buff, 1, cutpoint, file);
  121.       fwrite(copy_buff, 1, cutpoint, mod);
  122.       }
  123.    fclose(mod);
  124.    while ((chunk = read_file(copy_buff, 1, CHUNK_SIZE, file)) > 0)
  125.       fwrite(copy_buff, 1, chunk, samp);
  126.    fclose(samp);
  127.    close_file(file);
  128.    }
  129.       
  130.    
  131.  
  132.  
  133. int main(argc, argv)
  134. int argc;
  135. char **argv;
  136.    {
  137.    struct song *song;
  138.    int i;
  139.    int default_type;
  140.  
  141.  
  142.    default_type = BOTH;
  143.  
  144.    for (i = 1; i < argc; i++)
  145.       {
  146.       song = do_scan_song(argv[i], NEW);
  147.       if (!song && error != NEXT_SONG)
  148.          song = do_scan_song(argv[i], OLD);
  149.       if (song)
  150.          {
  151.          dump_song(song); 
  152.          split_module(argv[i], song->samples_start);
  153.          release_song(song);
  154.          }
  155.       }
  156.    return 0;
  157.    }
  158.  
  159.  
  160.  
  161. void sync_audio(f, p)
  162. void (*f) P((GENERIC));
  163. GENERIC p;
  164.     {
  165.     }
  166.  
  167. void audio_ui(c)
  168. int c;
  169.     {
  170.     }
  171.